package pers.course.week5;

import java.util.Scanner;

public class CircleCount {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        int m = 3;
        int[] number = new int[num];
        for (int i = 0; i < num; i++) {
            number[i] = i + 1;
        }
        int count = 1;
        int result = 0;
        int index = 0;
        while(num != 0) {
            if (index == number.length) {
                index = 0;
            }
            if (count == m && number[index] != 0) {
                number[index] = 0;
                num--;
                count++;
                if (count == m + 1) {
                    count = 1;
                }
            }
            if (number[index] != 0) {
                count++;
                if (count == m + 1) {
                    count = 1;
                }
            }
            index++;
        }
        result = index;
        System.out.println(result);
    }
}
